/*
** massfunc.hh
** Login : <David@sandrock.lrde.epita.fr>
** Started on  Mon Apr  7 17:48:28 2003 David Lesage
** $Id: massfunc.hh 52 2003-05-19 08:14:55Z burrus_n $
** 
** Copyright (C) 2003 David Lesage
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef   	MASSFUNC_HH_
# define   	MASSFUNC_HH_

namespace evz
{

  template <class E>
  class MassFunc
  {
  public:
    virtual float operator()(E event) const = 0;
  };

  template <class E>
  class MassPlus : public MassFunc<E>
  {
  public:
    MassPlus(const MassFunc<E>& m1, const MassFunc<E>& m2)
      : m1(m1), m2(m2)
    {}

    float operator()(E event) const
    {
      return m1(event) + m2(event);
    }

  private:
    const MassFunc<E>& m1;
    const MassFunc<E>& m2;
  };

  template <class E>
  class MassTimes : public MassFunc<E>
  {
  public:
    MassTimes(const MassFunc<E>& m1, const MassFunc<E>& m2)
      : m1(m1), m2(m2)
    {}

    float operator()(E event) const
    {
      return m1(event) * m2(event);
    }

  private:
    const MassFunc<E>& m1;
    const MassFunc<E>& m2;
  };

  template <class E>
  class MassDiv : public MassFunc<E>
  {
  public:
    MassDiv(const MassFunc<E>& m1, const MassFunc<E>& m2)
      : m1(m1), m2(m2)
    {}

    float operator()(E event) const
    {
      return m1(event) / m2(event);
    }

  private:
    const MassFunc<E>& m1;
    const MassFunc<E>& m2;
  };

  template <class E>
  class MassComplement : public MassFunc<E>
  {
  public:
    MassComplement(const MassFunc<E>& m)
      : m(m)
    {}

    float operator()(E event) const
    {
      return 1. - m(event);
    }

  private:
    const MassFunc<E>& m;
  };

  template <class E>
  class MassValue : public MassFunc<E>
  {
  public:
    MassValue(float value) : value_(value)
    {}

    float operator()(E) const
    {
      return value_;
    }    
  private:
    float value_;
  };

} // end of namespace evz

#endif	    /* !MASSFUNC_HH_ */
